﻿using System;
using System.Collections.Generic;
using System.Text;

using OurSite.Business.Category;
using OurSite.Business.Event;
using OurSite.Business.Picture;

namespace OurSite.WebAdmin.HTMLHelpers
{
    public static class HTMLHelper
    {
        public static string EventSimpleList(ICollection<Event> evts)
        {
            StringBuilder sb = new StringBuilder();
            foreach(Event evt in evts)
            {
                sb.Append("<a href='/Event.aspx/EditEvent/" + evt.EventCode + "'>");
                sb.Append(evt.Name + "<br/>");
                sb.Append("</a>");
                foreach(Event sub in evt.SubEvents)
                {
                    sb.Append("&nbsp;&nbsp;&nbsp;<a href='/Event.aspx/EditEvent/" + sub.EventCode + "'>");
                    sb.Append(sub.Name + "<br/>");
                    sb.Append("</a>");    
                }

            }

            return sb.ToString();
        }

        public static string CategoryOptionList(ICollection<Category> categories)
        {
            StringBuilder sb = new StringBuilder();
            foreach (Category category in categories)
            {
                sb.Append("<option value='" + category.Id + "'>");
                sb.Append(category.Name);
                sb.Append("</option>");
            }

            return sb.ToString();
        }

        public static string EventCategoryTable(IList<Category> eventCategories)
        {
            StringBuilder sb = new StringBuilder();

            if (eventCategories != null)
            {
                foreach (Category c in eventCategories)
                {
                    if (c.ParentCategory != null)
                    {
                        sb.Append("<tr>");
                        sb.Append("<td>" + c.ParentCategory.Name + "</td>");
                        sb.Append("<td> -> </td>");
                        sb.Append("<td>" + c.Name + "</td>");


                        sb.Append("<td><img src='/content/images/cancel.png' onclick=\"deleteEventCategory('" + c.Id + "')\"> </td></tr>");
                        sb.Append("</tr>");
                    }
                }
            }
            return sb.ToString();
        }

        public static string PeopleCheckList(IList<People> people)
        {
            StringBuilder sb = new StringBuilder();
            foreach(People person in people)
            {
                string first = person.FirstName.Replace(@"""", @"\""");
                string last = person.LastName.Replace(@"""", @"\""");
                string maiden = person.MaidenName.Replace(@"""", @"\""");
                
                string dob = person.BirthDate.HasValue ? person.BirthDate.Value.ToShortDateString() : string.Empty;
                sb.Append("<input type='checkbox' id='people' value='" + person.PeopleId + "'>");
                sb.Append("<a class='cursor' onclick='peopleEditOpen(\"" + person.PeopleId + "\", \"" + first + "\",\"" + last + "\",\"" + maiden + "\"," + person.IsHuman.ToString().ToLower() + ", \"" + dob + "\")' >" + person.Name + "</a>");
                sb.Append("<br/>");
            }

            return sb.ToString();
        }
    }
}
